﻿using System;
using System.Data;

using HsTec.Mobile.Green.BLL;


public partial class OnlineReport_OnlineReportManage : System.Web.UI.Page
{
    ReportAnalysisBLL rab = new ReportAnalysisBLL();
    ReportAnalysisOnlineBLL bll = new ReportAnalysisOnlineBLL();
    string sAreaId = String.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((string)Session["Baimasoft_Pers_ID"] == null)
        {
            Response.Redirect("../Logon.aspx");
        }
        GridView1.Attributes.Add("BorderColor", "LightSkyBlue");
        lstArea.Attributes.Add("onclick", "FindSelectedItems(this," + txtArea.ClientID + ");");
        chkArea.Attributes.Add("onclick", "chkAll(this)");
        //控制控件显示
        sAreaId = (string)Session["Baimasoft_Report"];
        if (!String.IsNullOrEmpty(sAreaId))
        {
            hidAreaid.Value = "1";
        }
        if (!IsPostBack)
        {
            BindGridViewData();
            this.sltAreaBind();
            sltStartYear.Value = DateTime.Now.Year.ToString();
            sltStartMonth.Value = string.Format("{0:D2}", DateTime.Now.Month);
            sltEndYear.Value = DateTime.Now.Year.ToString();
            sltEndMonth.Value = string.Format("{0:D2}", DateTime.Now.Month);
            this.HiddenID.Value = "";
        }
    }

    private void sltAreaBind()
    {
        lstArea.DataSource = bll.GetAreaList(sAreaId);
        lstArea.DataTextField = "Name";
        lstArea.DataValueField = "ID";
        lstArea.DataBind();
    }
    private void BindGridViewData()
    {
        DataView mydv = bll.GetList(GetSearchString());
        GridView1.DataSource = mydv;
        GridView1.DataBind();
        this.HiddenID.Value = "";
    }
    private string GetSearchString()
    {
        string searchStr = "(1=1)";

        string sArea = String.Empty;
        for (int i = 0; i < lstArea.Items.Count; i++)
        {
            if (lstArea.Items[i].Selected == true)
            {
                sArea += sArea == String.Empty ? lstArea.Items[i].Value : "," + lstArea.Items[i].Value;
            }
        }
        if (String.IsNullOrEmpty(sAreaId) || sAreaId == "0")
        {
            if (sArea != "")
            {
                searchStr += " and Area_ID in (" + sArea + ") ";
            }
        }
        else
        {
            searchStr += " and Area_ID =" + sAreaId + "";
        }
        searchStr += " and Years  >='" + sltStartYear.Value + sltStartMonth.Value + "'  and Years  <='" + sltEndYear.Value + sltEndMonth.Value + "' ";
        string sAduit = sltAduit.Value.Trim();
        if (!String.IsNullOrEmpty(sAduit))
            searchStr += " and AuditState  ='" + sAduit + "' ";
        return searchStr;
    }
    protected void btnAduit_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(HiddenID.Value.Trim()))
        {
            bll.Aduit(HiddenID.Value.TrimEnd(','));
            BindGridViewData();
        }
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(HiddenID.Value.Trim()))
        {
            bll.Delete(HiddenID.Value.TrimEnd(','));
            BindGridViewData();
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindGridViewData();
    }
    protected void linkBtnGo_Click(object sender, EventArgs e)
    {

    }
    protected void GridView1_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
    {

    }
    protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            if (e.Row.Cells[7].Text.Trim() == "0")
            {
                e.Row.Cells[7].Text = "未审核";
            }
            else if (e.Row.Cells[7].Text.Trim() == "1")
            {
                e.Row.Cells[7].Text = "未通过";
            }
            else
            {
                e.Row.Cells[7].Text = "通过";
            }
            e.Row.Cells[8].Text = DateTime.Parse(e.Row.Cells[8].Text.Trim()).ToString("yyyy-MM-dd");
        }
    }
    protected void GridView1_Sorting(object sender, System.Web.UI.WebControls.GridViewSortEventArgs e)
    {

    }
}
